import { BasicColumn } from "/@/components/Table"
import { FormSchema } from "/@/components/Table"
import { JVxeTypes, JVxeColumn } from "/@/components/jeecg/JVxeTable/types"
import { listAllDataSource } from "../datasource/datasource.api"
export const columns: BasicColumn[] = [
  {
    title: "序号",
    dataIndex: "id",
    ifShow: false,
    width: 60,
  },
  {
    title: "数据源",
    dataIndex: "datasourceName",
    width: 120,
  },
  {
    title: "表名称",
    dataIndex: "tableName",
    width: 140,
  },
  {
    title: "表描述",
    dataIndex: "tableComment",
    width: 180,
    // customRender:render.renderAvatar,
  },
  {
    title: "创建时间",
    dataIndex: "createdAt",
    width: 150,
  },
]

export const formSchema: FormSchema[] = [
  {
    label: "",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: "用户账号",
    field: "userName",
    component: "Input",
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    // dynamicRules: ({model,schema}) =>rules.duplicateCheckRule("sys_user", "userName",model,schema,true),
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "datasourceId",
    label: "数据源",
    component: "Select",
  },
  {
    label: "表名称",
    field: "tableName",
    component: "Input",
  },
  {
    label: "表描述",
    field: "tableComment",
    component: "Input",
  },
]

export const baseInfoFormSchema: FormSchema[] = [
  {
    label: "id",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: "表名称",
    field: "tableName",
    component: "Input",
  },
  {
    label: "表描述",
    field: "tableComment",
    component: "Input",
  },
  {
    label: "备注",
    field: "remark",
    component: "InputTextArea",
    colProps: {
      span: 12,
    },
  },
]

export const importDocumnetTableFormSchema: FormSchema[] = [
  {
    field: "datasourceId",
    label: "数据源",
    component: "Select",
    defaultValue: "1",
    required: true,
    componentProps: () => {
      return {
        options: [],
      }
    },
  },
  {
    label: "必填标志",
    field: "requiredFlag",
    required: true,
    defaultValue: "Y",
    helpMessage: "是否是必填项列中的必填项标志, eg: 文档中 [Y] 表示必填, [N或者空]表示非必填, 则这里输入 [Y]",
    component: "Input",
  },
  {
    field: "divider-table-pk",
    component: "Divider",
    label: "主键",
  },
  {
    label: "主键名称",
    field: "pkName",
    required: true,
    defaultValue: "id",
    component: "Input",
  },
  {
    label: "主键类型",
    field: "pkType",
    required: true,
    defaultValue: "bigint",
    component: "Input",
  },
  {
    label: "主键长度",
    field: "pkLength",
    required: true,
    defaultValue: "0",
    component: "Input",
  },
  // {
  //   label: '主键标志',
  //   field: 'pkFlag',
  //   required: true,
  //   helpMessage: "是否为主键列中的是主键标志, eg: 文档中 [是] 表示主键, [否或者空]表示非主键, 则这里输入 [是]",
  //   component: 'Input',
  // },
  {
    field: "divider-table-field",
    component: "Divider",
    label: "表列配置",
  },
  {
    label: "描述列名",
    field: "columnCommentCol",
    required: true,
    helpMessage: "对应数据库中列描述",
    component: "Input",
  },
  {
    label: "类型列名",
    field: "columnTypeCol",
    required: true,
    helpMessage: "对应到数据库字段类型",
    component: "Input",
  },

  {
    label: "名称列名",
    field: "columnNameCol",
    required: true,
    helpMessage: "对应数据库字段名称",
    component: "Input",
  },

  {
    label: "是否必填列名",
    field: "requiredCol",
    required: true,
    component: "Input",
  },
  {
    field: "divider-table-index",
    component: "Divider",
    label: "表索引",
  },
  {
    label: "索引列名",
    field: "tableIndexCol",
    helpMessage: "表格中索引列名称",
    component: "Input",
  },
  {
    label: "索引列标志",
    field: "tableIndexFlag",
    helpMessage: "索引列标志, 比如单元格 = Y, 表示当前是一个索引字段, 不填则非索引字段",
    defaultValue: "Y",
    component: "Input",
  },
  {
    label: "索引类型",
    field: "indexType",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "lcp_mysql_table_index_type",
      placeholder: "请选择索引类型",
      // stringToNumber: true
    },
  },
  {
    label: "索引方法",
    field: "indexMethod",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "lcp_mysql_table_index_method",
      placeholder: "请选择索引方法",
      // stringToNumber: true
    },
  },
  {
    label: "文档",
    field: "filePath",
    component: "MyFileUpload",
    componentProps: {
      fileMax: 1,
    },
  },
]

export const genInfoFormSchema: FormSchema[] = [
  // {
  //   label: '表类型',
  //   field: 'tableCategory',
  //   component: 'JDictSelectTag',
  //   componentProps: {
  //     dictType: 'table_category',
  //     placeholder: '类型',
  //     showChooseOption: false
  //   },
  // },
  {
    label: "生成包路径",
    field: "packageName",
    helpMessage: "生成在哪个包下, 例如: com.demo.system",
    component: "Input",
  },
  {
    label: "生成模块名",
    field: "moduleName",
    helpMessage: "可以理解为子系统名(/${moduleName}/${businessName}), 例如: system,",
    component: "Input",
  },
  {
    label: "生成业务名",
    field: "businessName",
    helpMessage: "可以理解功能英文名(/${moduleName}/${businessName}), 例如: user",
    component: "Input",
  },
  {
    label: "生成功能名",
    field: "functionName",
    helpMessage: "用作类描述, 例如: 用户",
    component: "Input",
  },
  // {
  //   label: '生成代码方式',
  //   field: 'genType',
  //   component: 'JDictSelectTag',
  //   componentProps: {
  //     dictType: 'gen_type',
  //     placeholder: '请选择方式',
  //     // stringToNumber:true
  //   },
  // },
]

// 表类型: 主子表相关配置
export const tableCategorySubFormSchema: FormSchema[] = [
  {
    label: "子表配置",
    field: "",
    colProps: { lg: 24, sm: 24 },
    component: "Divider",
  },
  {
    label: "子表的表名",
    field: "subTableName",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "tpl_category",
      placeholder: "请选择方式",
      showChooseOption: false,
    },
  },
  {
    label: "子表的外键名",
    field: "subTableFkName",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "tpl_category",
      placeholder: "请选择方式",
      showChooseOption: false,
    },
  },
]

// 表类型: 树形表相关配置
export const tableCategoryTreeFormSchema: FormSchema[] = [
  {
    label: "树型表配置",
    field: "",
    colProps: { lg: 24, sm: 24 },
    component: "Divider",
  },
  {
    label: "编码字段",
    field: "tplCategory",
    helpMessage: "树显示的编码字段名， 如：dept_id",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "tpl_category",
      placeholder: "请选择方式",
      showChooseOption: false,
    },
  },
  {
    label: "父编码字段",
    field: "tplCategory",
    helpMessage: "树显示的父编码字段名， 如：parent_Id",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "tpl_category",
      placeholder: "请选择方式",
      showChooseOption: false,
    },
  },
  {
    label: "名称字段",
    field: "tplCategory",
    helpMessage: "树节点的显示名称字段名， 如：dept_name",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "tpl_category",
      placeholder: "请选择方式",
      showChooseOption: false,
    },
  },
]

export const genCodeFormSchema: FormSchema[] = [
  {
    label: "生成表id",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: "表名",
    field: "tableName",
    colProps: { lg: 12, md: 12 },
    dynamicDisabled: true,
    component: "Input",
  },
  {
    label: "类名称",
    field: "className",
    required: true,
    colProps: { lg: 12, md: 12 },
    component: "Input",
  },
  {
    label: "短类名称",
    field: "shortClassName",
    required: true,
    colProps: { lg: 12, md: 12 },
    component: "Input",
  },
  {
    label: "方法名称",
    field: "methodName",
    required: true,
    colProps: { lg: 12, md: 12 },
    component: "Input",
  },
  {
    label: "短方法名称",
    field: "shortMethodName",
    required: true,
    colProps: { lg: 12, md: 12 },
    component: "Input",
  },
  {
    label: "作者名",
    field: "author",
    required: true,
    colProps: { lg: 12, md: 12 },
    component: "MyAutoComplete",
  },
  {
    label: "包路径",
    field: "packageName",
    required: true,
    colProps: { lg: 12, md: 12 },
    helpMessage: "包名com.demo.system, 其中com.demo就是包名",
    // slot: 'packageName',
    component: "MyAutoComplete",
  },
  {
    label: "模块名",
    field: "moduleName",
    required: true,
    colProps: { lg: 12, md: 12 },
    helpMessage: "包名com.demo.system, 其中system就是模块名",
    component: "Input",
  },
  {
    label: "功能名",
    field: "functionName",
    required: true,
    colProps: { lg: 12, md: 12 },
    helpMessage: "可以作为接口名称, 例如: user",
    component: "Input",
  },
  {
    label: "删除前缀",
    field: "delPrefix",
    colProps: { lg: 12, md: 12 },
    helpMessage: "删除前缀（表名sys_user删除前缀sys_对应bean为User）多前缀逗号隔开",
    component: "Input",
  },
  {
    field: "templateGroupId",
    component: "Select",
    colProps: { lg: 12, md: 12 },
    required: true,
    label: "代码模板组",
    componentProps: ({ formModel, formActionType }) => {
      return {
        options: [],
      }
    },
  },
  {
    label: "版本号",
    required: true,
    field: "genVersion",
    colProps: { lg: 12, md: 12 },
    component: "Input",
  },
  {
    label: "说明",
    field: "description",
    component: "InputTextArea",
    helpMessage: "可以用作类描述",
    colProps: { span: 24 },
    componentProps: {
      autoSize: {
        minRows: 3,
        maxRows: 5,
      },
    },
  },
]

export const genTableColumns: JVxeColumn[] = [
  { title: "ID", key: "id", type: JVxeTypes.hidden },
  {
    title: "字段名称",
    key: "columnName",
    type: JVxeTypes.input,
    width: 200,
    defaultValue: "",
    validateRules: [{ required: true, message: "${title}不能为空" }],
  },
  {
    title: "字段类型",
    key: "columnType",
    type: JVxeTypes.input,
    width: 140,
    defaultValue: "32",
    validateRules: [{ required: true, message: "${title}不能为空" }],
  },
  {
    title: "字段长度",
    key: "columnLength",
    type: JVxeTypes.input,
    width: 140,
    defaultValue: "0",
    validateRules: [{ required: true, message: "${title}不能为空" }],
  },
  {
    title: "小数点",
    key: "columnScale",
    type: JVxeTypes.input,
    width: 140,
    defaultValue: "0",
    validateRules: [{ required: true, message: "${title}不能为空" }],
  },
  {
    title: "主键",
    key: "isPk",
    type: JVxeTypes.checkbox,
    disabled: true,
    width: 90,
    customValue: [true, false],
    defaultChecked: false,
  },
  { title: "允许空值", key: "isNullable", type: JVxeTypes.checkbox, width: 80, customValue: [true, false], disabled: true, defaultChecked: true },
  {
    title: "字段描述",
    key: "columnComment",
    type: JVxeTypes.input,
    minWidth: 200,
    defaultValue: "",
    placeholder: "请输入${title}",
    validateRules: [
      {
        required: false,
        message: "请输入${title}",
      },
    ],
  },
]

/**
 * 页面属性配置( dbTableColumns 和 pageAttributeColumns 都属于gen_table_column中的字段)
 */
export const pageAttributeColumns: JVxeColumn[] = [
  // 表的列id
  { title: "ID", key: "id", type: JVxeTypes.hidden },
  {
    title: "字段名称",
    key: "columnName",
    type: JVxeTypes.input,
    width: 200,
    defaultValue: "not value",
    validateRules: [{ required: true, message: "${title}不能为空" }],
  },
  {
    title: "字段描述",
    key: "columnComment",
    type: JVxeTypes.input,
    width: 220,
    defaultValue: "",
  },
  {
    title: "属性名",
    key: "attrName",
    type: JVxeTypes.input,
    width: 220,
    defaultValue: "",
  },
  {
    title: "插入",
    key: "isInsert",
    type: JVxeTypes.checkbox,
    width: 80,
    customValue: [true, false],
    defaultChecked: false,
  },
  {
    title: "编辑",
    key: "isEdit",
    type: JVxeTypes.checkbox,
    width: 80,
    customValue: [true, false],
    defaultChecked: false,
  },
  {
    title: "列表",
    key: "isList",
    type: JVxeTypes.checkbox,
    width: 80,
    customValue: [true, false],
    defaultChecked: false,
  },
  {
    title: "详情",
    key: "isDetail",
    type: JVxeTypes.checkbox,
    width: 80,
    customValue: [true, false],
    defaultChecked: false,
  },
  {
    title: "查询",
    key: "isQuery",
    type: JVxeTypes.checkbox,
    width: 80,
    customValue: [true, false],
    defaultChecked: false,
  },
  {
    title: "查询方式",
    key: "queryType",
    type: JVxeTypes.select,
    width: 140,
    options: [],
    dictType: "query_type",
    placeholder: "请选择",
  },
  {
    title: "显示类型",
    key: "htmlType",
    type: JVxeTypes.select,
    width: 140,
    defaultValue: "input",
    options: [],
    dictType: "lcp_ui_compoent",
    placeholder: "请选择",
  },
  {
    title: "字典类型",
    key: "dictType",
    type: JVxeTypes.selectDictSearch,
    minWidth: 200,
    placeholder: "请输入",
    props: {},
  },
]
